package utility;

import java.sql.ResultSet;
import java.sql.SQLException;

import dbmanager.DBManager;
import dbmanager.GetIdName;

public class Removeperfix 
{
	DBManager database;
	GetIdName gid;
	public void getResult(String prefix)
	{
		ResultSet rs =database.getSelect("SELECT mid,pid,pv,vt FROM property_details  where lower(vt) like lower('"+prefix+".%')");
		prefix = prefix.toLowerCase() +".";
		try {
			while(rs.next())
			{
				
				String pv = rs.getString("pv");
				if(pv.equals("0"))
					pv = rs.getString("vt").toLowerCase();
				else
					pv = gid.getItem(pv).toLowerCase();
				System.out.println(pv);
				String mid=rs.getString("mid");
				String newpv = pv.replace(prefix, "");
				System.out.println("pv="+pv+" new pv="+newpv);
				String QUERY="Select * from  property_details  where mid='"+mid+"' and "+ "pid='"+rs.getString("pid")+"' and lower(vt)=lower('"+pv+"')";
				System.out.println(QUERY);
			    database.getUpdate("update property_details set vt ='"+newpv+"' where mid='"+mid+"' and "+ "pid='"+rs.getString("pid")+"' and lower(vt)=lower('"+pv+"')");	
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void setdatabase(DBManager database)
	{
		this.database = database;
		gid= new GetIdName(database);
	}
	
	public static void main(String[] args) 
	{
		DBManager database =new DBManager();
		database.getConnect();
		Removeperfix remove  =new Removeperfix();
		remove.setdatabase(database);
		remove.getResult("dispatch");
	}
}
